<template>
    <div class="xtx-goods-page">
        <div class="container" v-if="goodsList">
            <!-- 面包屑 -->
            <XtxBread>
                <XtxBreadItem to="/">首页</XtxBreadItem>
                <XtxBreadItem :to="`/category/${goodsList.categories[1]?.id}`">{{ goodsList.categories[1]?.name }}
                </XtxBreadItem>
                <XtxBreadItem :to="`/category/sub/${goodsList.categories[0]?.id}`">{{ goodsList.categories[0]?.name }}
                </XtxBreadItem>
                <XtxBreadItem>{{ goodsList.name }}</XtxBreadItem>
            </XtxBread>
            <!-- 商品信息 -->
            <div class="goods-info">
                <!-- 商品信息左边 -->
                <div class="goods-info-left">
                    <GoodsImage :imgList="goodsList.mainPictures" />
                    <GoodsSales />
                </div>
                <!-- 商品信息右边 -->
                <div class="goods-info-right">
                    <GoodsName />
                </div>
            </div>
            <!-- 商品推荐 -->
            <GoodsRelevant :goodsId="route.params.id" :key="goodsList.id" />
            <!-- 商品详情 -->
            <div class="goods-footer">
                <div class="goods-article">
                    <!-- 商品+评价 -->
                    <GoodsTabs />
                    <!-- 注意事项 -->
                    <div class="goods-warn"></div>
                </div>
                <!-- 24热榜+专题推荐 -->
                <div class="goods-aside">
                    <GoodsHot :goodsId="goodsList.id" :type="1" />
                    <GoodsHot :goodsId="goodsList.id" :type="2" />
                    <GoodsHot :goodsId="goodsList.id" :type="3" />
                </div>
            </div>
        </div>
    </div>
</template>

<script>
import GoodsRelevant from './components/GoodsRelevant.vue'
import GoodsImage from './components/GoodsImage.vue'
import GoodsSales from './components/GoodsSales.vue'
import GoodsName from './components/GoodsName.vue'
import GoodsTabs from './components/GoodsTabs.vue'
import GoodsHot from './components/GoodsHot.vue'
export default {
    name: 'XtxGoodsPage',
    components: { GoodsRelevant }
}
</script>

<script setup>
import { useRoute } from 'vue-router'
import { ref, watch, provide } from 'vue'
import { findGoods } from '@/apis/goods'

const route = useRoute()
const goodsList = ref(null)

provide("goodsList", goodsList)

watch(() => route.params.id, async () => {
    try {
        const { result } = await findGoods(route.params.id)
        goodsList.value = result
    } catch (err) {
        console.log(err);
    }

}, { immediate: true })
</script>

<style scoped lang='less'>
.goods-info {
    min-height: 600px;
    background: #fff;
    display: flex;

    .goods-info-left {
        width: 580px;
        height: 600px;
        padding: 30px 50px;
    }

    .goods-info-right {
        flex: 1;
        padding: 30px 30px 30px 0;
    }
}

.goods-footer {
    display: flex;
    margin-top: 20px;

    .goods-article {
        width: 940px;
        margin-right: 20px;
    }

    .goods-aside {
        width: 280px;
        min-height: 1000px;
    }
}

.goods-warn {
    min-height: 600px;
    background: #fff;
    margin-top: 20px;
}
</style>